<?php
class Controller_Search extends Controller_Action
{	
	public function __construct(Controller_Front $frontController)
	{
		parent::__construct('search', $frontController);
	}
	
	public function indexAction()
	{
		$this->view()->display('topmenu.tpl');
		
	}
	
	public function searchAction()
	{
		$criteria = new Criteria();
		$criteria->add(TagsPeer::NAME, $_POST['search'], Criteria::EQUAL);
		$tag = TagsPeer::doSelectOne($criteria);
		
		$criteria->clear();
	    $criteria->add(NewstagsPeer::ID_TAG, $tag->getIdTag(), Criteria::EQUAL);
	    
	    $newsTags = NewstagsPeer::doSelect($criteria);
	    
	    foreach ($newsTags as $newsTag) {
	    	$news = $newsTag->getNews();
	    }
	    $this->assign('news', $news);
	    //$this->view()->display('topmenu.tpl');
		$this->view()->display('search.tpl');
	}
     
}
	
